package zoptio.wicket.mooeditable;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.resources.CompressedResourceReference;

public class MooEditableBehavior extends AbstractAjaxBehavior {

	private static final ResourceReference MOOEDITABLE_JAVASCRIPT = 
		new CompressedResourceReference(MooEditableBehavior.class, "MooEditable-1.11.js");

	private static final ResourceReference MOOTOOLS_JAVASCRIPT = 
		new CompressedResourceReference(MooEditableBehavior.class, "mootools-1.11.js");

	private static final ResourceReference MOOEDITABLE_CSS = 
		new CompressedResourceReference(MooEditableBehavior.class, "css/MooEditable.css");

	@Override
	public void renderHead(IHeaderResponse response) {
		super.renderHead(response);
		response.renderJavascriptReference(MOOTOOLS_JAVASCRIPT);
		response.renderJavascriptReference(MOOEDITABLE_JAVASCRIPT);
		response.renderCSSReference(MOOEDITABLE_CSS);
		response.renderJavascript("var " + getComponent().getMarkupId() + ";", null);
		response.renderOnDomReadyJavascript(getComponent().getMarkupId() + " = $('"+ getComponent().getMarkupId() +"').mooEditable();");
	}
	
	@Override
	protected void onBind() {
		super.onBind();
		getComponent().setOutputMarkupId(true);
	}

	@Override
	public void onRequest() {
	}

}
